<template>
  <div>
    <el-table
      :data="menuList"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
      border
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <!-- prop：对应列内容的字段名 -->
      <el-table-column prop="id" label="菜单编号"> </el-table-column>
      <el-table-column prop="title" label="菜单名称"> </el-table-column>
      <el-table-column label="菜单图标">
        <template slot-scope="scoped">
          <div>
            <i :class="scoped.row.icon"></i>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="url" label="菜单地址"> </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scoped">
          <div>
            <el-button type="primary" v-show="scoped.row.status == 1"
              >启 用</el-button
            >
            <el-button type="info" v-show="scoped.row.status == 2"
              >禁 用</el-button
            >
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="操作">
        <template slot-scope="scoped">
          <div>
            <el-button @click="edit(scoped.row.id)">编 辑</el-button>
            <el-button type="warning" @click="del(scoped.row.id)"
              >删 除</el-button
            >
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { mapActions, mapGetters } from "vuex";
import { menuDelete } from "../../../request/api";
import { successAlert, warningAlert } from "../../../utils/alert";
export default {
  computed: {
    ...mapGetters({
      menuList: "menu/list",
    }),
  },
  methods: {
    ...mapActions({
      asyncMenuList: "menu/asyncChangeList",
    }),
    del(id) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          menuDelete({ id: id }).then((res) => {
            if (res.data.code == 200) {
              successAlert(res.data.msg);
              //重新请求列表数据
              this.asyncMenuList();
            } else {
              warningAlert(res.data.msg);
            }
          });
        })
        .catch(() => {
          warningAlert("已取消删除");
        });
    },
    edit(id){
      this.$emit("edit",id)
      // menuEdit({id:id}).then(res=>{
      //   console.log(res);
      // })
    }
  },
  mounted() {
    //页面一进来就请求列表数据
    this.asyncMenuList();
  },
};
</script>

<style>
</style>